home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-05-16 | 7.5 KB | 347 lines | [TEXT/CWIE] |
- /*
- *
- *
- */
-
-
- // ===========================================================================
- // <PP Starter Source>.cp ©1994-1995 Metrowerks Inc. All rights reserved.
- // ===========================================================================
- //
- // This file contains the starter code for a PowerPlant application
-
- #include "ISpTestMain.h"
- #include <Types.h>
- #include "InputSprocket.h"
-
- #include <LGrowZone.h>
- #include <LWindow.h>
- #include <PP_Messages.h>
- #include <PP_Resources.h>
- #include <PPobClasses.h>
- #include <UDrawingState.h>
- #include <UMemoryMgr.h>
- #include <URegistrar.h>
- #include <LEditField.h>
- #include <Events.h>
-
- #include "ISpTestGlobals.h"
- #include "ISpEventPane.h"
- #include "ISpElementView.h"
- #include "ISpLQuitWindow.h"
-
- // put declarations for resource ids (ResIDTs) here
-
- const ResIDT window_Sample = 1; // EXAMPLE
-
- Boolean EventProc(EventRecord *inEvent);
- Boolean EventProc(EventRecord *inEvent)
- {
- if (gMyApp == nil) { return false; }
-
- if (inEvent->what == updateEvt)
- {
- gMyApp->DispatchEvent(*inEvent);
- }
-
- return false;
- }
-
- // ===========================================================================
- // • Main Program
- // ===========================================================================
-
- void main(void)
- {
- ISpGetGlobalElementList(&gElementList);
-
- ISpElementList_Extract( gElementList,
- kMaxGlobalElements,
- &gNumElements,
- gElementBuffer);
-
- gElement = gElementBuffer[gCurElement];
-
- gStatus = ISpElementList_New(0, 0, &gElementList, 0);
-
- // Set Debugging options
- SetDebugThrow_(debugAction_Alert);
- SetDebugSignal_(debugAction_Alert);
-
- InitializeHeap(3); // Initialize Memory Manager
- // Parameter is number of Master Pointer
- // blocks to allocate
-
- // Initialize standard Toolbox managers
- UQDGlobals::InitializeToolbox(&qd);
-
- new LGrowZone(20000); // Install a GrowZone function to catch
- // low memory situations.
-
- CPPStarterApp theApp; // replace this with your App type
- gMyApp = &theApp;
- theApp.Run();
-
- }
-
-
- // ---------------------------------------------------------------------------
- // • CPPStarterApp // replace this with your App type
- // ---------------------------------------------------------------------------
- // Constructor
-
- CPPStarterApp::CPPStarterApp()
- {
- URegistrar::RegisterClass(ISpElementView::class_ID, ISpElementView::CreateISpElementViewStream);
- URegistrar::RegisterClass(ISpEventPane::class_ID, ISpEventPane::CreateISpEventPaneStream);
- URegistrar::RegisterClass(LQuitWindow::class_ID, LQuitWindow::CreateLQuitWindowStream);
-
- // Register functions to create core PowerPlant classes
-
- RegisterAllPPClasses();
- }
-
-
- // ---------------------------------------------------------------------------
- // • ~CPPStarterApp // replace this with your App type
- // ---------------------------------------------------------------------------
- // Destructor
- //
-
- CPPStarterApp::~CPPStarterApp()
- {
- ISpElement_DisposeVirtual(kNumNeeds, mVirtualElements);
- }
-
- // ---------------------------------------------------------------------------
- // • StartUp
- // ---------------------------------------------------------------------------
- // This function lets you do something when the application starts up.
- // For example, you could issue your own new command, or respond to a system
- // oDoc (open document) event.
-
- void
- CPPStarterApp::StartUp()
- {
- LWindow *theWindow;
-
- theWindow = LWindow::CreateWindow(1, this);
- theWindow->Show();
-
- theWindow = LWindow::CreateWindow(2, this);
- theWindow->Show();
-
-
- }
-
- // ---------------------------------------------------------------------------
- // • ObeyCommand
- // ---------------------------------------------------------------------------
- // Respond to commands
-
- Boolean
- CPPStarterApp::ObeyCommand(
- CommandT inCommand,
- void *ioParam)
- {
- Boolean cmdHandled = true;
-
- switch (inCommand) {
-
- // Deal with command messages (defined in PP_Messages.h).
- // Any that you don't handle will be passed to LApplication
-
- case cmd_New:
- // EXAMPLE, create a new window
- break;
-
-
- case cmd_Suspend:
- gStatus = ISpSuspend();
- break;
-
- case cmd_Resume:
- gStatus = ISpResume();
- break;
-
- case cmd_NextElement:
- gStatus = noErr;
- gCurElement = (gCurElement + 1) % gNumElements;
- gElement = gElementBuffer[gCurElement];
- break;
-
- case cmd_PrevElement:
- gStatus = noErr;
- gCurElement = (gCurElement + gNumElements - 1) % gNumElements;
- gElement = gElementBuffer[gCurElement];
- break;
-
- case cmd_AddElement:
- gStatus = ISpElementList_AddElements( gElementList,
- gCurElement,
- 1,
- &gElement);
- break;
-
- case cmd_DeleteElement:
- gStatus = ISpElementList_RemoveElements( gElementList,
- 1,
- &gElement);
- break;
-
- case cmd_UIStart:
- gStatus = ISpInit( kNumNeeds,
- mNeeds,
- mVirtualElements,
- 'ISpT',
- 'foob',
- 0,
- 0,
- 0);
- break;
-
- case cmd_UIConfigure:
- gStatus = ISpConfigure(&EventProc);
- break;
-
- case cmd_UIStop:
- gStatus = ISpStop();
- break;
-
- default:
- cmdHandled = LApplication::ObeyCommand(inCommand, ioParam);
- break;
- }
-
- return cmdHandled;
- }
-
- // ---------------------------------------------------------------------------
- // • FindCommandStatus
- // ---------------------------------------------------------------------------
- // This function enables menu commands.
- //
-
- void
- CPPStarterApp::FindCommandStatus(
- CommandT inCommand,
- Boolean &outEnabled,
- Boolean &outUsesMark,
- Char16 &outMark,
- Str255 outName)
- {
-
- switch (inCommand) {
-
- // Return menu item status according to command messages.
- // Any that you don't handle will be passed to LApplication
-
- case cmd_New: // EXAMPLE
- outEnabled = false;
- break;
-
- case cmd_Suspend:
- case cmd_Resume:
- case cmd_NextElement:
- case cmd_PrevElement:
- case cmd_AddElement:
- case cmd_DeleteElement:
- case cmd_UIStart:
- case cmd_UIConfigure:
- case cmd_UIStop:
- outEnabled = true; // enable the New command
- break;
-
- default:
- LApplication::FindCommandStatus(inCommand, outEnabled,
- outUsesMark, outMark, outName);
- break;
- }
- }
-
- void CPPStarterApp::EventResume (const EventRecord &inMacEvent)
- {
- ISpResume();
-
- LApplication::EventResume(inMacEvent);
- }
-
- void CPPStarterApp::EventSuspend (const EventRecord &inMacEvent)
- {
- ISpSuspend();
-
- LApplication::EventSuspend(inMacEvent);
- }
-
- void CPPStarterApp::InitNeeds(void)
- {
- ISpNeed tempNeeds[kNumNeeds] =
- {
- {
- "\pForward Thrust",
- kIconSuiteID_YThrust,
- kISpElementKind_Axis,
- kISpElementLabel_YAxis,
- 0
- },
- {
- "\pSide Thrust",
- kIconSuiteID_XThrust,
- kISpElementKind_Axis,
- kISpElementLabel_XAxis,
- 0
- },
- {
- "\pVertical Thrust",
- kIconSuiteID_ZThrust,
- kISpElementKind_Axis,
- kISpElementLabel_ZAxis,
- 0
- },
- {
- "\pLook",
- kIconSuiteID_Look,
- kISpElementKind_Movement,
- kISpElementLabel_None,
- 0
- },
- {
- "\pFire",
- kIconSuiteID_Fire,
- kISpElementKind_Button,
- kISpElementLabel_Fire,
- 0
- },
- {
- "\pThrust",
- kIconSuiteID_Thrust,
- kISpElementKind_Button,
- kISpElementLabel_Fire,
- 0
- },
- {
- "\pPause",
- kIconSuiteID_Pause,
- kISpElementKind_Button,
- kISpElementLabel_None,
- kISpNeedFlag_NoMultiConfig
- },
- {
- "\pStart/Stop",
- kIconSuiteID_Start,
- kISpElementKind_Button,
- kISpElementLabel_Start,
- kISpNeedFlag_NoMultiConfig
- }
- };
-
-
- int itr;
- for(itr = 0; itr < kNumNeeds; itr++)
- {
- mNeeds[itr] = tempNeeds[itr];
- }
-
- ISpElement_NewVirtualFromNeeds(kNumNeeds, mNeeds, mVirtualElements, 0);
-
- }